﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>PurchasePlan</title>
    @*Easyui需要引入的文件*@
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link href="~/Content/jquery-easyui-1.4.5/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.4.5/themes/icon.css" rel="stylesheet" />
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script type="text/javascript" src="~/Content/Site.js"></script>
    <script src="~/Content/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(function () {
            //初始化datagrid
            InitGrid();
            InitDialog();
            $('#btnReload').click(function () {
                $("#grid").datagrid("reload");
            });
            //ajax提交修改表单
            $('#ok').click(function () {
                $('#errdiv').removeClass('dis');
                $('#form').submit();
            });
            $('#cancel').click(function () {
                $('#dd').dialog('close');
            });
            $('#add').click(function () {
                $('#form')[0].reset();
                $('#key').val(0);
                $('#PurchaseNo').attr('placeholder', '编号：C+日期+序号');
                $('#PurchaseNo').removeAttr('disabled');
                $('#PurchaseDate').removeAttr('disabled');
                $('#dd').dialog('open');
            });
            $('#edit').click(function () {
                $('#PurchaseNo').attr('disabled', 'disabled');
                $('#PurchaseDate').attr('disabled', 'disabled');
                getAjax("../PSS_PurchasePlan/LoadForm",
                        { id: $('#del_id').val() }, function (data) {
                            var data = eval("(" + data + ")");
                            SetWebControls(data);
                        });
                $('#key').val(1);
                $('#dd').dialog('open');
            });

            $('#del').click(function () {
                getAjax("../PSS_PurchasePlan/Del", { id: $('#del_id').val() }, function (data) {
                    if ($('#del_id').val() == null || $('#del_id').val() == "")
                        return false;
                    if (data) {
                        $.messager.alert('提示', '操作成功!');
                        $('#dd').dialog('close');
                        $("#grid").datagrid("reload");
                        return true;
                    }
                    else {
                        $.messager.alert('提示', '操作失败!');
                        return false;
                    }
                });
            });
        });

        //实现对DataGird控件的绑定操作
        function InitGrid() {
            $('#grid').datagrid({
                url: '../PSS_PurchasePlan/LoadList',
                singleSelect: true,
                fit: true,
                nowrap: true,//单行显示
                autoRowHeight: false,
                striped: false,     //斑马纹
                collapsible: true,      //可折叠
                pagination: true,
                pageSize: 20,
                border: false,
                fitColumns: true,       //自适应列宽
                rownumbers: true,
                columns: [[
                     { title: '采购单号', field: 'PurchaseNo' },
                     {
                         title: '采购日期', field: 'PurchaseDate',
                         formatter: function (value, row, index) {
                             var date = value.split(' ');
                             return date[0];
                         }
                     },
                     { title: '操作工号', field: 'OperateNo' },
                     {
                         title: '创建日期', field: 'OperateDate',
                         formatter: function (value, row, index) {
                             var date = value.split(' ');
                             return date[0];
                         }
                     },
                     {
                         title: '采购状态', field: 'PurchaseStatus',
                         formatter: function (value, row, index) {
                             if (value == 0) {
                                 return "未采购";
                             } else if (value == 1) {
                                 return "采购中";
                             } else
                                 return "已采购";
                         }
                     },
                     { title: '备注', field: 'Remark' },
                ]],
                toolbar: '#tb',
                onDblClickRow: function (rowIndex, rowData) {
                    addTab('采购详单-' + rowData['PurchaseNo'], '../PSS_PurchasePlanDetail/PurchasePlanDetail?PurchaseNo=' + rowData['PurchaseNo']);
                },
                onClickRow: function (index, row) {
                    $('#del_id').val(row['PurchaseNo']);
                }
            })
            var p = $('#grid').datagrid('getPager');
            $(p).pagination({
                beforePageText: '第',
                afterPageText: '页   共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });
        };

        //初始化对话框
        function InitDialog() {
            $('#dd').dialog({
                title: '修改信息',
                width: 300,
                height: 300,
                top: ($(window).height() - 300) * 0.5,      //居中
                left: ($(window).width() - 300) * 0.5,
                closed: true,
                cache: false,
                modal: true,
                buttons: '#dlg-buttons'
            });
        }
    </script>
    <script>
        //表单验证和提交
        $(function () {
            $('#form').validate({
                rules: {
                    PurchaseNo: {
                        required: true
                    },
                    PurchaseDate: {
                        required: true
                    }
                },
                messages: {
                    PurchaseNo: "采购单号不能为空！",
                    PurchaseDate: "采购日期不能为空！"
                },
                errorLabelContainer: '#errdiv>ul',
                wrapper: 'li',
                submitHandler: function (form) {
                    var postData = GetWebControls("#form");
                    getAjax("/PSS_PurchasePlan/AcceptClick",
                        postData, function (data) {
                            if (data == 1) {
                                $.messager.alert('提示', '操作成功!');
                                $('#dd').dialog('close');
                                $("#grid").datagrid("reload");
                                return true;
                            }
                            else if (data == -1) {
                                $.messager.alert('提示', '已存在该记录或单号重复，请重新填写!');
                                return false;
                            }
                            else {
                                $.messager.alert('提示', '操作失败!');
                                return false;
                            }
                        });
                },
                invalidHandler: function (form, validator) {  //不通过回调
                    return false;
                }
            });
        });
    </script>
    <style>
        .dis {
            display: none;
        }

        .td_col-180 {
            width: 180px;
        }
    </style>
</head>
<body style="margin:2px;padding:0">
    <div>
        <input id="del_id" type="hidden" name="del_id" value="" />
        <div style="position:fixed;width:100%;height:100%">
            <div id="tabs" class="easyui-tabs" data-options="fit:true,border:false,plain:true">
                <div title="采购单" style="text-align:center;">
                    <table id="grid"></table>
                </div>
            </div>

        </div>
        <div id="tb" style="padding:3px">
            <a id="add" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
            <a id="edit" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">修改</a>
            <a id="del" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
            <a id="btnReload" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">刷新</a>
        </div>
    </div>
    <div id="dd" class="easyui-dialog">
        <form id="form" name="form" method="post">
            <input id="key" type="hidden" value="" />
            <table style="margin:8px">
                <tr>
                    <td>采购单号:</td>
                    <td><input type="text" id="PurchaseNo" name="PurchaseNo" class="td_col-180" value="" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>采购日期:</td>
                    <td><input type="text" id="PurchaseDate" name="PurchaseDate" value=" " class="td_col-180" onclick="WdatePicker()" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>操作工号:</td>
                    <td><input type="text" id="OperateNo" name="OperateNo" value="" class="td_col-180" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>操作日期:</td>
                    <td><input type="text" id="OperateDate" name="OperateDate" value="" class="td_col-180" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>采购状态:</td>
                    <td>
                        <select id="PurchaseStatus" name="PurchaseStatus" class="td_col-180">
                            <option value="0">未采购</option>
                            <option value="1">采购中</option>
                            <option value="2">已采购</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>备注:</td>
                    <td><textarea id="Remark" name="Remark" class="td_col-180"></textarea></td>
                </tr>
            </table>
            <div class="errdiv" id="errdiv">
                <ul></ul>
            </div>
            <div id="dlg-buttons">
                <a id="ok" href="#" class="easyui-linkbutton" iconcls="icon-ok">确定</a>
                <a id="cancel" href="#" class="easyui-linkbutton" iconcls="icon-cancel">取消</a>
            </div>

        </form>
    </div>
</body>
</html>
